package com.film.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.FilmSeat;
import com.film.domain.FilmShowings;
import com.film.service.SeatService;
import com.film.service.ShowingsService;
import com.film.service.impl.SeatServiceImpl;
import com.film.service.impl.ShowingsServiceImpl;

@WebServlet("/selectSeats.do")
public class ChoseSeatController extends HttpServlet{
	
	private SeatService seatService = new SeatServiceImpl();
	private ShowingsService showingsService = new ShowingsServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String showingsId = request.getParameter("showingsId");
		List<FilmSeat> soldSeats = seatService.selectSoldSeat(Integer.parseInt(showingsId));
		List<FilmSeat> allSeats = seatService.selectAllSeat();
		FilmShowings showingsInfo = showingsService.seleShowingsById(Integer.parseInt(showingsId), 0);
		HttpSession session = request.getSession();
		session.setAttribute("allSeats", allSeats);
		session.setAttribute("soldSeats", soldSeats);
		session.setAttribute("showingsInfo", showingsInfo);
		response.sendRedirect("seat.jsp");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
